$(function(){

var phone = document.querySelector('#phone');
var phones_yc = document.querySelector('.phones_yc')
var pass1 = document.querySelector('#password');
var pass2 = document.querySelector('.password2');
var phone_pas = document.querySelector('.phone_pas');
var btn = document.querySelector('.btn');
var phone_yc = document.querySelector('.phone_yc');
var del = document.querySelector('.del');


phone.oninput = function () {
    var idPhone = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    phones_yc.innerHTML = idPhone.test(this.value) ? '通过验证' : '未通过验证';
}

var passReg = [
    /^.{6,16}$/, // 限定长度为6-16位
    /[A-Z]+/, // 验证大写字母
    /[a-z]+/, //验证小写字母
    /\d+/, // 验证数字
    /\W+/ // 验证特殊字符 
];

pass1.oninput = function() {
    var that = this;
    var check = passReg.map(function(elm) { // 遍历数组使用 数组种的每一个正则去验证当然输入框的内容
        return elm.test(that.value);
    });
    // 计数 check有几个符合条件的

    var strength = check.reduce(function(obj, current) {
        current && obj.count++;
        return obj;
    }, {
        count: 0
    });

    

    switch (strength.count) {
        case 1:
        case 2:
            pass1.nextElementSibling.innerHTML = '密码太简单,不符合规范';
            break;
        case 3:
            if (check[0]) pass1.nextElementSibling.innerHTML = "弱";
            break;
        case 4:
            if (check[0]) pass1.nextElementSibling.innerHTML = "中";
            break;
        case 5:
            pass1.nextElementSibling.innerHTML = "强";

    }
}

pass2.oninput = function () {
    if(pass2.value != pass1.value){
        pass2.nextElementSibling.innerHTML = '密码不一致，请重新输入';
        return true;
    }else{
        pass2.nextElementSibling.innerHTML ='密码正确';
        return false;
        
    }
    
}



phone_yc.innerHTML = '';
    function random(min,max){
        return Math.floor(Math.random()*(max - min + 1) + min)
    }
    btn.onclick  =function(){

    
        function getCode() {
            var code = '';
            for (var i = 0; i < 6; i++) {
                var type = random(1, 3);
                switch (type) {
                    case 1:
                        code += String.fromCharCode(random(48, 57)); //数字
                        break;
                    case 2:
                        code += String.fromCharCode(random(65, 90)); // 大写字母
                        break;
                    case 3:
                        code += String.fromCharCode(random(97, 122)); // 小写字母
                        break;
                }
            }
            return code;
        }
            phone_yc.innerHTML = getCode();
    }

    
    phone_pas.oninput = function () {
        // var yzm = document.querySelector('.yxm');
        if(phone_pas.value != phone_yc.innerHTML ){
            del.innerHTML = '验证码不一致，请重新输入';
            return true;
        }else{
           del.innerHTML  ='验证码正确';
            return false;
            
        }
        
    }






})







// function random(min,max){
//     return Math.floor(Math.random()*(max-min +1) +min);
// }




// function getCode(){
//     var code = '';
//     for(var i = 0; i < 6; i++){
//         var type = random(1,3);
//         switch(type){
//             case 1:
//                 code += String.fromCharCode(random(48,57));//数字
//                 break;
//             case 2:
//                 code += String.fromCharCode(random(65,90));//大写字母
//                 break;
//             case 3:
//                 code += String.fromCharCode(random(97,122));//小写字母
//                 break;
//         }
//     }
//     return code;
    
// }



  
 
// $('.phone_yc').innerhtml += $('.btn').on('click',function(){
//     getCode()
   
    
// });

    // var str = '';
    //  $('.phone_yc').innerhtml += $('.btn').on('click',function(){
    //     getCode()
    //    return
        
    // });
    // console.log(str)

 
